﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Frogger
{
    class FontSprite : MoveableEntity
    {

        bool __isVisible = true;
        public bool IsVisible
        {
            get
            {
                return this.__isVisible;
            }
            set
            {
                this.__isVisible = value;
            }
        }

        public FontSprite(Texture2D textureImage, Vector2 position,
            Point frameSize, int collisionOffset, Point currentFrame, Point sheetSize,
            Vector2 speed, string name, int scoreValue)
            : base(textureImage, position, frameSize, collisionOffset, currentFrame,
            sheetSize, speed, name, scoreValue, 1f)
        {
        }

        //Return the collision Rectangle
        public override Rectangle collisionRect
        {
            get
            {
                return new Rectangle(
                    (int)(__position.X + (__collisionOffset * __scale)),
                    (int)(__position.Y + (__collisionOffset * __scale)),
                    (int)((__frameSize.X - (__collisionOffset * 2)) * __scale),
                    (int)((__frameSize.Y - (__collisionOffset * 2)) * __scale));
            }
        }

        public override void Update(GameTime gameTime, Rectangle clientBounds)
        {  

            this.__position += this.direction;

            //Update animation frame

            if (this.__isVisible)
            {
                this.__timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
                if (this.__timeSinceLastFrame > this.__millisecondsPerframe)
                {
                    this.__timeSinceLastFrame = 0;
                    ++this.__currentFrame.X;
                    if (this.__currentFrame.X >= this.__sheetSize.X)
                    {
                        this.__currentFrame.X = 0;
                        ++this.__currentFrame.Y;
                        if (this.__currentFrame.Y >= this.__sheetSize.Y)
                        {
                            this.__currentFrame.Y = 0;
                            this.__isVisible = false;
                        }
                    }
                }
            }
            base.Update(gameTime, clientBounds);
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            //Draw the sprite
            if (this.__isVisible)
            {
                spriteBatch.Draw(this.__textureImage,
                    this.__position,
                    new Rectangle(this.__currentFrame.X * this.__frameSize.X,
                        this.__currentFrame.Y * this.__frameSize.Y,
                        this.__frameSize.X, this.__frameSize.Y),
                        Color.White, 0f, Vector2.Zero,
                        this.__scale, SpriteEffects.None, 0);
            }
        }

        //Getters 
        public override Vector2 direction
        {
            get
            {
                return this.__speed;
            }
            protected set
            {
                this.__speed = value;
            }
        }
    }
}
